<template>
	<view class="indent-detail">
		<unicloud-db ref="udb" v-slot:default="{data, loading, error, options}" :options="options" :collection="collectionList" :getone="true" :manual="true" @load="hanldeData">
			<view v-if="error">{{error.message}}</view>
			<view v-else-if="loading">
			  <uni-load-more :contentText="loadMore" status="loading"></uni-load-more>
			</view>
			<view v-else-if="data">
				<indentStatusWrapVue :indent="data" :type="type" @reload="reload" />
				<indentContentVue :indent="data" />
				<indentInfoVue :indent="data" />
			</view>
		</unicloud-db>
	</view>
</template>

<script>
	import indentContentVue from './cpns/indent-content.vue';
	import indentInfoVue from './cpns/indent-info.vue';
	import indentStatusWrapVue from './cpns/indent-status-wrap.vue';
	import { enumConverter } from '../../js_sdk/validator/dish-order-form.js'
	
	const db = uniCloud.database()
	export default {
		name: 'indent-detail',
		data() {
		  return {
				indentData: {},
		    queryWhere: '',
		    collectionList: [ 
					db.collection('dish-order-form').getTemp(),
					db.collection('dish-user').field('openid,nickname as text,avatar_url,phone,status,role,sex,push_clientid,create_time,last_login_date').getTemp(),
					db.collection('dish-role').field('role_name as text, role_id').getTemp(),
					db.collection('dish-dining-place').field('name as text, _id').getTemp(),
					db.collection('dish-order-form-goods').getTemp(),
				],
		    loadMore: {
		      contentdown: '',
		      contentrefresh: '',
		      contentnomore: ''
		    },
		    options: {
		      // 将scheme enum 属性静态数据中的value转成text
		      ...enumConverter
		    }
		  }
		},
		components: {indentContentVue, indentStatusWrapVue, indentInfoVue},
		onLoad(e) {
		  this._id = e.id
			uni.hideLoading()
		},
		onReady() {
			if (this._id) {
				this.collectionList = [ 
					db.collection('dish-order-form').where('_id=="' + this._id + '"').getTemp(),
					db.collection('dish-user').field('openid,nickname as text,avatar_url,phone,status,role,sex,push_clientid,create_time,last_login_date').getTemp(),
					db.collection('dish-role').field('role_name as text, role_id').getTemp(),
					db.collection('dish-dining-place').field('name as text, _id').getTemp(),
					db.collection('dish-order-form-goods').getTemp(),
					db.collection('dish-order-form-guest-type').getTemp(),
				]
			}
		},
		onShareAppMessage(e) {
			return {
				title: '分享点餐',
				path: '/pages/order/order?indentId='+this.indentData._id,
			}
		},
		methods: {
			hanldeData(data) {
				console.log(data);
				this.indentData = data
			},
			reload() {
				this.$refs.udb.loadData({
				  clear: true
				})
			}
		}
	}
</script>

<style lang="scss">
	.indent-detail {
		padding: 20rpx;
		min-height: calc(100vh - 40rpx);
		background-color: #f2f2f2;
		
	}
</style>
